<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateOrdersTable extends Migration
{

    protected $tableName = 'orders';

    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create($this->tableName, function (Blueprint $table) {
            $table->increments('id');
            $table->string('trade_no')->unique()->comment('订单号');
            $table->char('wx_transaction_id', 32)->comment('微信支付订单号	');
            $table->unsignedInteger('user_id')->comment('用户ID');
            $table->unsignedTinyInteger('quantity')->comment('数量');
            $table->string('name')->comment('商品名称');
            $table->decimal('total_amount')->comment('总价');
            $table->decimal('discount_amount')->comment('优惠总价');
            $table->decimal('actual_amount')->comment('实际价钱');
            $table->decimal('paid_amount')->comment('已支付价钱');
            $table->timestamp('paid_at')->nullable()->comment('付款时间');
            $table->unsignedTinyInteger('status')->comment('订单状态');
            $table->string('remark')->nullable()->comment('备注');

            $table->timestamps();
            $table->softDeletes();

            $table->index('user_id');
        });
        DB::statement("ALTER TABLE `$this->tableName` comment '订单表'");
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists($this->tableName);
    }
}
